package com.cg.service.impl;

import com.cg.service.SmsService;
import com.cg.vo.SendOrderNumByPhone;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName MessageImpl
 * @Description TODO
 * @Author CG
 * @Date 2024/1/12 13:25
 **/
@Component
@RocketMQMessageListener(consumerGroup = "orderConsumerGroup",topic = "orderTopic",messageModel = MessageModel.BROADCASTING)
public class MessageImpl implements RocketMQListener<SendOrderNumByPhone> {


    private final Logger logger = LoggerFactory.getLogger(MessageImpl.class);

    @Resource
    private SmsService service;

    @Override
    public void onMessage(SendOrderNumByPhone sendOrderNumByPhone) {
        logger.info("发送小程序消息:"+sendOrderNumByPhone.getPhone()+"预约成功，预约编号为："+sendOrderNumByPhone.getOrderNum());
        String orderNum = sendOrderNumByPhone.getOrderNum();
        //截取最后四位
        String substring = orderNum.substring(orderNum.length() - 4);
        service.sendCode(sendOrderNumByPhone.getPhone(),substring);
        logger.info("短信发送成功："+substring+",接收人"+sendOrderNumByPhone.getPhone());
    }



}
